package com.hui.blog_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hui.blog_server.entity.User;
import com.hui.blog_server.entity.Userinfo;
import com.hui.blog_server.mapper.UserMapper;
import com.hui.blog_server.mapper.UserinfoMapper;
import com.hui.blog_server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;


/**
 * @author 彩色的小灰
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserinfoMapper userinfoMapper;

    @Override
    public Userinfo login(String email, String password) {
        QueryWrapper<User> userWrapper = new QueryWrapper<>();
        userWrapper.eq("email", email);
        User user = userMapper.selectOne(userWrapper);
        boolean isMatch = Objects.equals(user.getPassword(), password);
        if (isMatch) {
            QueryWrapper<Userinfo> userinfoWrapper = new QueryWrapper<>();
            userinfoWrapper.eq("user_id", user.getId());
            return userinfoMapper.selectOne(userinfoWrapper);
        } else {
            return null;
        }
    }
}
